﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OneSys.Misc
{
    internal class DzsddzSoftLicense : License
    {
        public override string LicenseKey { get { return string.Empty; } }

        public override void Dispose()
        {

        }
    }

    public class DzsddzSoftLicenseProvider : LicenseProvider
    {
        [System.Runtime.InteropServices.DllImport("DzSddzSoft.dll")]
        static extern int SetSddzSoft();
        [System.Runtime.InteropServices.DllImport("DzSddzSoft.dll")]
        static extern void GetErrMessage(StringBuilder sb, int len, int langID);
        [System.Runtime.InteropServices.DllImport("DzSddzSoft.dll")]
        static extern bool IsHwIDMatched(StringBuilder sb);


        public override License GetLicense(LicenseContext context, Type type, object instance, bool allowExceptions)
        {
            if (ValidateLicense())
            {
                return new DzsddzSoftLicense();
            }
            return null;
        }

        private bool ValidateLicense()
        {

            if (SetSddzSoft() != 0)
            {

                return true;

            }


            var sb = new StringBuilder(sbyte.MaxValue);
            CultureInfo culture = CultureInfo.CreateSpecificCulture("zh_CN");

            GetErrMessage(sb, sb.Capacity, culture.LCID);

            XtraMessageBox.Show(sb.ToString());
            return false;
        }
    }
}
